package com.zqq.baselibrary.ui.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import com.zqq.baselibrary.utils.NetWorkUtils
import org.greenrobot.eventbus.EventBus

/**
 * 实现监听网络状态变更的广播接收器
 * 未用
 * @author zqq on 2018/7/31
 */
class NetworkConnectChangedReceiver : BroadcastReceiver() {

    private val TAG = "NetworkConnectChanged"

    override fun onReceive(context: Context, intent: Intent) {
        //*判断当前的网络连接状态是否可用*/
        var isConnected = NetWorkUtils.isConnected(context)
        Log.e(TAG, "onReceiver:当前网络$isConnected")

        //postSticky是粘性发送，不需要先注册。
        EventBus.getDefault().post(NetworkChangeEvent(isConnected))
    }

}